package ltd.jdsoft.cute.channel.helper;

import java.security.PublicKey;

import ltd.jdsoft.cute.cache.CacheClient;
import ltd.jdsoft.cute.cache.callback.GetCallback;
import ltd.jdsoft.cute.channel.model.Orgnization;
import ltd.jdsoft.cute.channel.service.OrgnizationService;
import ltd.jdsoft.cute.common.rsa.KeyInitialzer;

/**
 * 公钥工具类，将公钥缓存起来
 * 
 * @author zhengzhq
 *
 */
public class PublicKeyHelper {

  public static PublicKey getPublicKey(Orgnization orgnization) {
    return CacheClient.get(OrgnizationService.keyUtil.getRecKey(".pk." + orgnization.getId()),
        new GetCallback<PublicKey>() {

          @Override
          public String getCacheGroup() {
            return null;
          }

          @Override
          public PublicKey getObject() {
            return KeyInitialzer.initPublicKey(orgnization.getPublicKey());
          }
        });
  }
}
